#!/bin/bash

java -version
if [ $? -eq 0 ]; then
  ver=$(java -version 2>&1 |awk 'NR==1{gsub(/"/,"");print $3}')
  if [ "${ver: 0: 3}" == "1.8" ];then
    echo "jdk版本是1.8"
  else
    echo "jdk版本不是1.8"
  fi

else
  wget https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html#license-lightbox
  mkdir /usr/local/jdk
  mv jdk-8u241-linux-x64.tar.gz /usr/local/jdk/jdk-8u241-linux-x64.tar.gz
  cd /usr/local/jdk
  tar -xzvf jdk-8u241-linux-x64.tar.gz
  rm jdk-8u241-linux-x64.tar.gz
  chmod 700 /etc/profile
  echo "#jdk config" >>/etc/profile
  echo "export JAVA_HOME=/usr/local/jdk/jdk1.8.0_241" >>/etc/profile
  echo "export JRE_HOME=$JAVA_HOME/jre" >>/etc/profile
  echo "export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib" >>/etc/profile
  echo "export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin" >>/etc/profile
  source /etc/profile
  echo "jdk 1.8 安装成功！"
fi